home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 602 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  62 lines

  1. Path: mothra.westworld.com!news
  2. From: art@osz.com (Art Schlefstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Template problem with Visual C++ 2.0
  5. Date: Fri, 05 Jan 1996 09:56:43 GMT
  6. Organization: Westworld Communications, Inc.
  7. Message-ID: <4cisvq$det@mothra.westworld.com>
  8. NNTP-Posting-Host: b8.westworld.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11.  
  12. I'm writing a small class based on templates that Visual C++ 2.0
  13. chokes on.  Here's a the .CPP file that I tried to compile:
  14.  
  15. ------------------------------------------------------------------
  16.  
  17. #include <stdio.h>
  18.  
  19. template <class T, int n>
  20. class CVector
  21.     {
  22.     public:
  23.     T data[n];
  24.     };
  25.  
  26. template <class T, int n>
  27. void test( CVector<T,n> &v )        /* line 13 */
  28.     {
  29.     printf("%f\n", (float) v.data[0]);
  30.     }
  31.  
  32. void main(void)
  33.     {
  34.     CVector<float,3> v1;
  35.     v1.data[0] = 3.14159;
  36.     test(v1);
  37.     }
  38.  
  39. ------------------------------------------------------------------
  40.  
  41. When I compile this in Visual C++ 2., I get the following messages:
  42.  
  43. Compiling...
  44. D:\users\CLAUDIO\vector\vector.cpp
  45. D:\users\CLAUDIO\vector\vector.cpp(13) : error C2975: 'CVector' :
  46. invalid template actual argument '#2', constant expression expected
  47. D:\users\CLAUDIO\vector\vector.cpp(16) : error C2997: 'test' :
  48. function parameter list must use template formal parameter 'n'
  49. D:\users\CLAUDIO\vector\vector.cpp(22) : fatal error C1903: unable to
  50. recover from previous error(s); stopping compilation
  51. Error executing cl.exe.
  52. vector.exe - 3 error(s), 2 warning(s)
  53.  
  54. This code compiles fine with gcc 2.6.3.  Any ideas?  Is this a bug
  55. in Visual C++?
  56.  
  57. Please e-mail responses because my news server has been acting up
  58. lately.
  59.  
  60.     Claudio Fahey
  61.  
  62.